<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>假用户管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>

<style>
    .layui-table-cell{  /*最后的pic为字段的field*/
        height: 100%;
        max-width: 100%;
    }
    #test-n2 {
        position: relative;
        min-height: 400px !important;
        width: 100% !important;
    }

    #test-n2  #layui-laydate1,#test-n2  #layui-laydate1 .layui-laydate-main,#test-n2 .layui-laydate-content table{
        width: 100%;
    }

    #test-n2 .layui-laydate-content table tbody{
        height:calc(100vh - 400px)!important;
    }
    .text_box{
        padding: 15px !important;
    }

    #test-n3 {
        position: relative;
        min-height: 350px !important;
        width: 100% !important;
    }

    #layui-laydate1,#layui-laydate2{
        width: 100% !important;
    }
    #test-n3  #layui-laydate1 .layui-laydate-main{
        width:50%;
    }

    #test-n3  #layui-laydate1 .layui-laydate-main table{
        width: 100% !important;
    }
    #test-n3 .layui-laydate-content table tbody{
        height:calc(100vh - 240px)!important;
    }
    .layui-laydate-main{
        width:100%;!important;
    }
</style>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">用户列表</div>
                <div class="layui-card-body">

                    <div class="layui-form-item layui-form">
                        <!--  <div class="layui-inline">
                             <div class="layui-inline">
                                 <div class="layui-btn-group test-table-operate-btn">
                                     <button class="layui-btn" data-type="addadmin">添加用户</button>
                                 </div>
                             </div>
                         </div> -->
                        <!--<div class="layui-inline">-->
                            <!--<label class="layui-form-label">手机</label>-->
                            <!--<div class="layui-input-block">-->
                                <!--<input type="text" name="search_user_tel" id="search_user_tel" placeholder="请输入" autocomplete="off" class="layui-input">-->
                            <!--</div>-->
                        <!--</div>-->
                        <!--<div class="layui-inline">-->
                            <!--<div class="layui-btn-group test-table-operate-btn">-->
                                <!--<button class="layui-btn" data-type="searchUserButton">-->
                                    <!--<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>-->
                                <!--</button>-->
                            <!--</div>-->
                        <!--</div>-->
                    </div>
                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate" lay-size="lg">



                    </table>

                    <script type="text/html" id="test-table-operate-barDemo">

                    </script>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set','upload'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,upload = layui.upload
            ,laydate = layui.laydate
            ,form = layui.form;

        table.render({
            elem: '#test-table-operate'
            ,url: "{:url('User/false_user')}"
            ,height: 'full-155'
            ,cols: [[
                {field:'uid',width:80,align:"center",  title: 'ID'}
                ,{field:'user_icon', align:"center",  title: '头像',style:"height:60px;",templet:function(d){
                        return "<img  style='width:50px;height:50px;' src=" +d.user_icon+ ">"
                    }}
                ,{field:'nickname',align:"center",title: '昵称'}
                ,{field:'sex',align:"center",title: '性别',templet:function(d){
                        if (d.sex == 0){
                            return "未设置";
                        }else if(d.sex == 1){
                            return "男";
                        }else if (d.sex == 2){
                            return "女";
                        }
                    }}
                ,{field:'create_time',align:"center",title: '注册时间'}

            ]]
            ,page: true
            ,limit: 20
        });

        form.render(null, 'component-form-group');

        var qiandaoData = '';  //签到详情data
        var uploadInst = upload.render({
            elem: '#test2'
            ,url: "{:url('Common/no_upload')}"
            ,multiple: false
            ,before: function(obj){
                obj.preview(function (index, file, result) {
                    $(".file-iteme").hide();
                    //上传完毕
                    $('#uploader-list').append(
                        '<div id="" class="file-iteme">' +
                        '<img style="width: 48px;height: 48px;" src=' + result + '>' +
                        '</div>'
                    );
                });
            }
            ,done: function(res){
                //如果上传失败
                if (res.code == 0) {
                    return layer.msg(res.msg);
                }
                //上传成功
                if (res.code == 1) {
                    $('#banner_image').val(res.data);
                    return layer.msg(res.msg);
                }
            }
        });
        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;
            if(obj.event === 'editpass'){
                $('#editPasswordUid').val(data.uid);
                var editpassmodal = layer.open({
                    title:'修改密码'
                    ,type: 1
                    ,shadeClose: true
                    ,area: admin.screen() < 2 ? ['60%'] : ['500px']
                    ,content: $('#editpassmodal')
                });

            } else if(obj.event === 'del'){
                layer.confirm('确认删除会员'+data.phone+'吗？删除之后将禁止一切操作，可恢复', function(index){
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: "{:url('User/delUser')}",
                        type: 'post',
                        dataType: 'json',
                        data: {uid:data.uid},
                        success: function(msg){
                            layer.close(loading);
                            if (msg === "1") {
                                obj.del();
                                layer.close(index);
                            }else{
                                layer.msg('删除失败',{icon:2,time:1000});
                            }
                        }
                    })

                });
            } else if(obj.event === 'showDetail'){                           //修改操作
                var loading = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                var uid = data.uid;
                $.ajax({
                    url: "{:url('User/userInfoDetail')}",
                    type: 'post',
                    dataType: 'json',
                    data: {uid:uid},
                    success: function(data){
                        layer.close(loading);
                        if (data.code === 0) {
                            if (data.data.rename){
                                $('#relname').html(data.data.rename);
                            }else{
                                $('#relname').html('未实名');
                            }
                            if (data.data.cardid){
                                $('#idcardnum').html(data.data.cardid);
                            }else{
                                $('#idcardnum').html('未实名');
                            }

                            $('#childNum').html(data.data.childNum);


                            var userDetailModal = layer.open({
                                title:'客户信息详情'
                                ,type: 1
                                ,shadeClose: true
                                ,area:['800px']
                                ,content: $('#userDetail')
                            });
                        }else{
                            layer.msg('获取信息失败',{icon:2,time:1000});
                        }
                    }
                })
            }
        });
        //开关修改管理员状态
        form.on('switch(is_use_switch)', function(obj){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json);

            var is_del = this.checked ? '0' : '1';

            $.ajax({
                url: "{:url('User/isStart')}",
                type: 'post',
                dataType: 'json',
                data: {uid:json.uid,is_del:is_del},
                success: function(info){
                    if (info.code === 0) {
                        layer.close(loading);
                    }else{
                        layer.msg('修改失败',{icon:2,time:1000},function(){
                            //layer.close(loading);
                            window.location.reload();
                        });
                    }
                }
            })
        });
        //日历插件调用方法
        function loding_date(datas){
            laydate.render({
                elem: '#test-n2'
                ,type: 'date'
                ,theme: 'grid'
                ,position: 'static'
                ,range: false
                ,isInitValue: false
                ,calendar: false
                ,btns:false
                ,ready: function(value){
                    hide_mr(value);
                }
                ,done: function(value, date, endDate){
                    hide_mr(value);
                }
                ,change:function(value,date){
                    hide_mr(value);
                }
                , mark:datas//重要json！

            });
        }

        function hide_mr(value){
            var mm = value.year+'-'+value.month+'-'+value.date;

            $('.laydate-theme-grid table tbody').find('[lay-ymd="'+mm+'"]').removeClass('layui-this');

        }
        //修改密码提交
        form.on('submit(editpasssubmit)', function(data){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var password = $('#editPassword').val();
            var passwordAgin = $('#editPasswordAgin').val();
            if (password !== passwordAgin){
                layer.close(loading);
                layer.msg('两次输入的密码不同',{icon:2,time:1000});
                return false;
            }
            $.ajax({
                url: "{:url('User/editpass')}",
                type: 'post',
                dataType: 'text',
                data: {data:data.field},
                success: function(info){
                    if (info === "1") {
                        layer.msg('修改成功',{icon:1,time:2000},function(){
                            layer.closeAll()
                        });
                    }else{
                        layer.close(loading);
                        layer.msg('修改失败',{icon:2,time:1000})
                    }
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        var $ = layui.$, active = {
            addadmin: function() {
                var addmodal = layer.open({
                    title: '添加用户'
                    , type: 1
                    , shadeClose: true
                    , area: admin.screen() < 2 ? ['100%'] : ['700px']
                    , content: $('#addmodal')
                });
            },
            searchUserButton:function(){
                var search_user_tel  = $('#search_user_tel').val();
                table.reload('test-table-operate', {
                    where: {
                        user_tel: search_user_tel
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                //return false;
            },

        };

        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //表单验证
        form.verify({
            password: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
        });

    });
</script>


</body>
</html>